package org.hp.controller;

import com.github.pagehelper.PageInfo;
import org.hp.bean.Case;
import org.hp.service.dictionary.CaseService;
import org.hp.util.Random;
import org.hp.util.ResultJson;
import org.hp.util.ReturnJsonData;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

@Controller
public class CaseController {
    @Resource
    CaseService caseService;

    @RequestMapping("/queryGene")
    @ResponseBody
    public void queryGenee(HttpServletRequest req, HttpServletResponse resp,Integer page, Integer limit, String cname){
        List<Case> list=caseService.queryGene(limit,page,cname);
        PageInfo<Case> casePageInfo=new PageInfo<Case>(list);
        ReturnJsonData.returnJson(ResultJson.success(casePageInfo),resp);
    }

    @RequestMapping("/queryGeneResult")
    public void queryGeneResultt(HttpServletRequest req, HttpServletResponse resp,Integer page, Integer limit, String cname){
        List<Case> list=caseService.queryGeneResult(limit,page,cname);
        PageInfo<Case> casePageInfo=new PageInfo<Case>(list);
        ReturnJsonData.returnJson(ResultJson.success(casePageInfo),resp);
    }

    @RequestMapping("/queryCheck")
    public void queryCheckk(HttpServletRequest req, HttpServletResponse resp,Integer page, Integer limit, String cname){
        List<Case> list=caseService.queryCheck(limit,page,cname);
        PageInfo<Case> casePageInfo=new PageInfo<Case>(list);
        ReturnJsonData.returnJson(ResultJson.success(casePageInfo),resp);
    }

    @RequestMapping("/queryDelGene")
    public void queryDelGenee(HttpServletRequest req, HttpServletResponse resp){
        List<Map> list=caseService.queryDelGene();
        ReturnJsonData.returnJson(ResultJson.success(list),resp);
    }

    @RequestMapping("/queryDelGeneResult")
    public void queryDelGeneResultt(HttpServletRequest req, HttpServletResponse resp){
        List<Map> list=caseService.queryDelGeneResult();
        ReturnJsonData.returnJson(ResultJson.success(list),resp);
    }

    @RequestMapping("/queryDelCheck")
    public void queryDelCheckk(HttpServletRequest req, HttpServletResponse resp){
        List<Map> list=caseService.queryDelCheck();
        ReturnJsonData.returnJson(ResultJson.success(list),resp);
    }

    @RequestMapping("/addGene")
    public void addGenee(HttpServletRequest req, HttpServletResponse resp, Case c){
        String genId= Random.GetId();
        c.setCidnum(genId);
        int i=caseService.addGene(c);
        ReturnJsonData.returnJson(i>0? ResultJson.success():ResultJson.error(),resp);
    }
    @RequestMapping("/addGeneResult")
    public void addGeneResultt(HttpServletRequest req, HttpServletResponse resp, Case c){
        String genId= Random.GetId();
        c.setCidnum(genId);
        int i=caseService.addGeneResult(c);
        ReturnJsonData.returnJson(i>0? ResultJson.success():ResultJson.error(),resp);
    }
    @RequestMapping("/addCheck")
    public void addCheckk(HttpServletRequest req, HttpServletResponse resp, Case c){
        String genId= Random.GetId();
        c.setCidnum(genId);
        int i=caseService.addCheck(c);
        ReturnJsonData.returnJson(i>0? ResultJson.success():ResultJson.error(),resp);
    }

    @RequestMapping("/delGene")
    public void delGenee(HttpServletRequest req, HttpServletResponse resp){
        Integer cid=Integer.valueOf(req.getParameter("cid"));
        int i=caseService.delGene(cid);
        ReturnJsonData.returnJson(i>0? ResultJson.success():ResultJson.error(),resp);
    }
    @RequestMapping("/delGeneResult")
    public void delGeneResultt(HttpServletRequest req, HttpServletResponse resp){
        Integer cid=Integer.valueOf(req.getParameter("cid"));
        int i=caseService.delGene(cid);
        ReturnJsonData.returnJson(i>0? ResultJson.success():ResultJson.error(),resp);
    }
    @RequestMapping("/delCheck")
    public void delCheckk(HttpServletRequest req, HttpServletResponse resp){
        Integer cid=Integer.valueOf(req.getParameter("cid"));
        int i=caseService.delGene(cid);
        ReturnJsonData.returnJson(i>0? ResultJson.success():ResultJson.error(),resp);
    }

    @RequestMapping("/returnGene")
    public void returnGenee(HttpServletRequest req, HttpServletResponse resp){
        Integer cid=Integer.valueOf(req.getParameter("cid"));
        int i=caseService.returnGene(cid);
        ReturnJsonData.returnJson(i>0? ResultJson.success():ResultJson.error(),resp);
    }
    @RequestMapping("/returnGeneResult")
    public void returnGeneResultt(HttpServletRequest req, HttpServletResponse resp){
        Integer cid=Integer.valueOf(req.getParameter("cid"));
        int i=caseService.returnGene(cid);
        ReturnJsonData.returnJson(i>0? ResultJson.success():ResultJson.error(),resp);
    }
    @RequestMapping("/returnCheck")
    public void returnCheckk(HttpServletRequest req, HttpServletResponse resp){
        Integer cid=Integer.valueOf(req.getParameter("cid"));
        int i=caseService.returnGene(cid);
        ReturnJsonData.returnJson(i>0? ResultJson.success():ResultJson.error(),resp);
    }

    @RequestMapping("/queryOneGene")
    public void queryOneGenee(HttpServletRequest req, HttpServletResponse resp,Integer cid){
        Case list=caseService.queryOneGene(cid);
        System.out.println(list.toString());
        ReturnJsonData.returnJson(ResultJson.success(list),resp);

    }
    @RequestMapping("/queryOneGeneResult")
    public void queryOneGeneResultt(HttpServletRequest req, HttpServletResponse resp,Integer cid){
        Case list=caseService.queryOneGeneResult(cid);
        System.out.println(list.toString());
        ReturnJsonData.returnJson(ResultJson.success(list),resp);

    }
    @RequestMapping("/queryOneCheck")
    public void queryOneCheckk(HttpServletRequest req, HttpServletResponse resp,Integer cid){
        Case list=caseService.queryOneCheck(cid);
        System.out.println(list.toString());
        ReturnJsonData.returnJson(ResultJson.success(list),resp);

    }
    @RequestMapping("/updateGene")
    public void updateGenee(HttpServletRequest req, HttpServletResponse resp,Case c){
        int i=caseService.updateGene(c);
        ReturnJsonData.returnJson(i>0? ResultJson.success():ResultJson.error(),resp);
    }


}
